<?php
//include ('functions/index.php');
$oForm = new cForm  ('changepass', 'changepass');
$oForm -> addInput  ('Oude wachtwoord', 'password')
	   -> addInput  ('Nieuwe wachtwoord', 'password')
	   -> addInput  ('Nieuwe wachtwoord (check)', 'password')
	   -> addButton ('Wijzig');

if ($oForm -> isPosted())
{
	$user = new cModel('user', 'user_id', $_SESSION ['user_id']);
	if ($user -> password == cFunctions :: hashPassword ($_POST ['Oude_wachtwoord']))
	{
		if ($_POST ['Nieuwe_wachtwoord'] == $_POST ['Nieuwe_wachtwoord_(check)'])
		{
			$user -> password = cFunctions :: hashPassword ($_POST ['Nieuwe_wachtwoord_(check)']);
			$user -> save ();
			echo 'Succes, je wachtwoord is gewijzigd.';
		}
		else
		{
			echo 'Sorry, je hebt in de laatste 2 velden niet dezelfde wachtwoorden ingevuld.' . cFunctions :: goBack ();
		}
	}
	else
	{
		echo 'Sorry, je hebt je oude wachtwoord niet goed ingevuld.' . cFunctions :: goBack ();
	}
}
else
{
	echo $oForm	-> output ();
}
/*
if (isset ($_SESSION ['username']) && IsRegistered ($_SESSION ['username']) == true)
{
	include ('includes/Zend/index.php');

	$oForm -> setAction ($_SERVER ['REQUEST_URI'])
		  -> setMethod ('post')
		  -> setAttrib ('class', 'zendform');

	$fOldPassword = new Zend_Form_Element_Password ('oldpassword');
	$fOldPassword -> setLabel ('Oude wachtwoord')
			    -> setRequired (true)
			    -> addFilter (new Zend_Filter_StringTrim ())
			    -> addValidator(new Zend_Validate_NotEmpty ());

	$fNewPassword = new Zend_Form_Element_Password ('newpassword');
	$fNewPassword -> setLabel ('Nieuwe wachtwoord')
			    -> setRequired (true)
			    -> addFilter (new Zend_Filter_StringTrim ())
			    -> addValidator(new Zend_Validate_NotEmpty ())
			    -> addValidator(new Zend_Validate_StringLength (array ('min' => 6)));

	$fNewPasswordRep = new Zend_Form_Element_Password ('newpasswordrep');
	$fNewPasswordRep -> setLabel ('Nieuwe wachtwoord herhalen')
				  -> setRequired (true)
				  -> addFilter (new Zend_Filter_StringTrim ())
				  -> addValidator(new Zend_Validate_NotEmpty ())
				  -> addValidator(new Zend_Validate_Identical ('newpassword'))
				  -> addValidator(new Zend_Validate_StringLength (array ('min' => 6)));

	$oForm -> addElement ($fOldPassword);
	$oForm -> addElement ($fNewPassword);
	$oForm -> addElement ($fNewPasswordRep);
	$oForm -> addElement ($btSubmit);
	$oForm -> addElement ($btReset);

	if ($_SERVER ['REQUEST_METHOD'] == 'POST' && $oForm -> isValid ($_POST))
	{
		$sQuery = "UPDATE `user` SET `password` = :sNewPassword WHERE `gebruikersnaam` = :sUsername;";
		try
		{
			$oStmt = $pPDO -> prepare ($sQuery);
			$oStmt -> bindParam (':sNewPassword', sha1 ('just to make it salt it thingie' . md5 ($_POST ['newpassword'])), PDO :: PARAM_STR);
			$oStmt -> bindParam (':sUsername', $_SESSION ['username'], PDO :: PARAM_STR);
			if ($oStmt -> execute ())
			{
				echo 'Je wachtwoord is veranderd.';
			}

		}
		catch (PDOException $e)
		{
			ePDOException :: writeMessage ($e);
		}
	}

	echo $oForm -> render (new Zend_View ());
}

set_include_path ('.:');
*/